<template>
  <!-- 头部部分 -->
  <header class="header">
    <h1>todos</h1>
    <input
      v-model.trim="task"
      class="new-todo"
      placeholder="请输入任务名称"
      autofocus
      @keyup.enter="fnAdd"
      @keyup.esc="task = ''"
    />
  </header>
</template>

<script>
export default {
  data() {
    return {
      task: "",
    };
  },
  methods: {
    fnAdd() {
      if (this.task === "") return alert("输入框不能为空");
      this.$emit("keyup-event", this.task);
      this.task = "";
    },
  },
};
</script>

<style></style>
